package org.aiforum.frountend.service;

import java.util.Date;
import java.util.List;

import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;

import org.aiforum.domain.Reply;
import org.aiforum.frountend.common.Response;
import org.aiforum.frountend.dao.ReplyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 联系我们业务实现
 * @author VIC
 *
 */
@Service("replyService")
@Transactional(value=TxType.REQUIRED)
public class ReplyServiceImpl implements ReplyService {
	
	@Autowired
	private ReplyDao replyDao;


	@Override
	public Response save(Reply entity) {
		// 设置状态和创建日期
		entity.setState(1);
		entity.setReplyDate(new Date());
		replyDao.persist(entity);
		Response response = new Response();
		response.setState(true);
		response.setMessage("Reply success.");
		return response;
	}

	@Override
	public List<Reply> queryByTopicId(int topicId) {
		String hql = "from Reply r where r.topicId = " + topicId;
		return replyDao.queryReplys(hql);
	}

}
